import { SET_LIST, DEL_LIST, ADD_LIST } from './actionsType'
const initState = {
	list: []
}


const reducer = (state = initState, action) => {
	const { type, payload } = action
	const { list } = state
	switch (type) {
		// 设置列表
		case SET_LIST:
			return {
				...state,
				list: payload
			}
		// 删除列表项
		case DEL_LIST:
			return {
				...state,
				list: [...list].filter(v => v.id !== payload.id)
			}
		// 添加列表项
		case ADD_LIST:
			return {
				...state,
				list: [payload, ...list]
			}
		default:
			return state
	}
}


export default reducer